package cz.possoft.explorer.resolver;

import java.util.HashMap;
import java.util.Map;

/**
 * This resolver can be used for array objects, where key is index of the item in array.<br>
 * S identifies type of single item for Array object.
 * 
 * @author <a href="mailto:mposolda@gmail.com">Marek Posolda</a>
 * @version $Revision$
 */
public class ArrayResolverImpl<S> implements Resolver<S[],Integer>
{
   public Map<Integer, Class<?>> getFields(Class<? super S[]> clazz, S[] array)
   {            
      Map<Integer, Class<?>> resultMap = new HashMap<Integer, Class<?>>();
      
      int counter=0;
      if (array != null)
      {
         for (S current : array)
         {
            resultMap.put(counter++, current.getClass());
         }
      }
      return resultMap;
   }
   
   public S getFieldValue(S[] array, Integer index)
   {
      return array[index];
   }
   
   public Class<Integer> getKeyClass()
   {
      return Integer.class;
   }

}

